Avoid more GFile<>uri roundtrips
authorMatthias Clasen <mclasen@redhat.com>
Fri, 24 Jul 2015 04:40:59 +0000 (00:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 27 Jul 2015 12:07:39 +0000 (08:07 -0400)
Make GtkSearchHit carry a GFile instead of an uri. Most of the
search engines already have the object around, and converting
to an uri and back is unnecessary extra work.

gtk/gtkfilechooserwidget.c
gtk/gtksearchengine.c
gtk/gtksearchengine.h
gtk/gtksearchenginemodel.c
gtk/gtksearchenginesimple.c
gtk/gtksearchenginetracker.c

index 9c51220310faef84829557a0d7976d04fba72473..689eaaa0859db981c5af0762cfc958c2757ef251 100644 (file)
@@ -7007,9 +7007,7 @@ search_engine_hits_added_cb (GtkSearchEngine      *engine,
   for (l = hits; l; l = l->next)
     {
       GtkSearchHit *hit = (GtkSearchHit *)l->data;
-      file = g_file_new_for_uri (hit->uri);
-      if (!file)
-        continue;
+      file = g_object_ref (hit->file);
       if (hit->info)
         {
           files_with_info = g_list_prepend (files_with_info, file);
index eff96923aac9e4e15f665d6fe4a25955f3bf2f5a..fbbb80b0d00e69ec302d4229079b86bee63521a1 100644 (file)
@@ -311,7 +311,7 @@ search_hit_equal (gconstpointer a, gconstpointer b)
   const GtkSearchHit *ha = (const GtkSearchHit *)a;
   const GtkSearchHit *hb = (const GtkSearchHit *)b;
 
-  return g_str_equal (ha->uri, hb->uri);
+  return g_file_equal (ha->file, hb->file);
 }
 
 
@@ -320,7 +320,7 @@ search_hit_hash (gconstpointer a)
 {
   const GtkSearchHit *ha = (const GtkSearchHit *)a;
 
-  return g_str_hash (ha->uri);
+  return g_file_hash (ha->file);
 }
 
 GtkSearchHit *
@@ -329,7 +329,7 @@ _gtk_search_hit_dup (GtkSearchHit *hit)
   GtkSearchHit *dup;
 
   dup = g_new (GtkSearchHit, 1);
-  dup->uri = g_strdup (hit->uri);
+  dup->file = g_object_ref (hit->file);
   if (hit->info)
     dup->info = g_object_ref (hit->info);
   else
@@ -341,7 +341,7 @@ _gtk_search_hit_dup (GtkSearchHit *hit)
 void
 _gtk_search_hit_free (GtkSearchHit *hit)
 {
-  g_free (hit->uri);
+  g_clear_object (&hit->file);
   g_clear_object (&hit->info);
   g_free (hit);
 }
index e49eeb8c79f65b95a798f3c59d083e866c67a979..c3d181274dde4642c169f80ca0d5838580dda424 100644 (file)
@@ -42,7 +42,7 @@ typedef struct _GtkSearchHit GtkSearchHit;
 
 struct _GtkSearchHit
 {
-  gchar *uri;
+  GFile *file;
   GFileInfo *info; /* may be NULL */
 };
 
index a7f00eec4dc70c05ef24e0ad2b6e0928ff186333..f245e1aa2148a69f85a0c5fcbbae7b26f736dfa5 100644 (file)
@@ -99,7 +99,7 @@ do_search (gpointer data)
 
               file = _gtk_file_system_model_get_file (model->model, &iter);
               hit = g_new (GtkSearchHit, 1);
-              hit->uri = g_file_get_uri (file);
+              hit->file = g_object_ref (file);
               hit->info = g_object_ref (info);
               hits = g_list_prepend (hits, hit);
             }
index 4db84ce7840747e790ee588277a4997d6fbccea1..1b5a31be9673a71056d24e2a70f5eb3bfe3dde2e 100644 (file)
@@ -248,7 +248,7 @@ visit_directory (GFile *dir, SearchThreadData *data)
           GtkSearchHit *hit;
 
           hit = g_new (GtkSearchHit, 1);
-          hit->uri = g_file_get_uri (child);
+          hit->file = g_object_ref (child);
           hit->info = g_object_ref (info);
           data->hits = g_list_prepend (data->hits, hit);
         }
index 7c4e063282ebdf4664e211929079705f44294b2c..bac7a09afda5a7e7dccef74be61efdede5b7db6a 100644 (file)
@@ -300,7 +300,7 @@ query_callback (GObject      *object,
 
       v = g_variant_iter_next_value (&iter);
       strv = g_variant_get_strv (v, NULL);
-      hit[i].uri = (gchar*)strv[0];
+      hit[i].file = g_file_new_for_uri (strv[0]);
       hit[i].info = NULL;
       g_free (strv);
       hits = g_list_prepend (hits, &hit[i]);